<!-- Modal -->
<div class="modal fade " id="addSpecificQuotaTypeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">维护具体指标</h3>
            </div>
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">维度</label>
                        <div class="col-sm-7">
                            <input id="specificDimensionName" type="text" class="form-control" style="width: 100%;"
                                   readonly>
                            <input id="specificDimensionId" type="hidden">
                            <input id="specificId" type="hidden">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">指标选择</label>
                        <div class="col-sm-7">
                            <select id="specificQuotaId" class="form-control select2" style="width: 100%;">
                            </select>
                        </div>
                    </div>
                    <div class="form-group" id="specificWeightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">指标权重</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="specificWeight">
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary pull-right" onclick="saveSpecificQuotaType()">保存
                    </button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>
<script>
    function specificInit(data) {
        $("#specificDimensionName").val("");
        $("#specificDimensionId").val("");
        $("#specificId").val("");
        $("#specificQuotaId option").remove();
        $("#specificWeight").val("");

        $("#specificDimensionName").val(data.name);
        $("#specificDimensionId").val(data.id);
        var url = "/scoremodel/quotainfo/list?modelId=" + data.modelId;

        getReq(url, function (result) {
            var html = "";
            var list = result;
            for (var i = 0; i < list.length; i++) {
                var o = list[i];
                html = html + "<option value='" + o.id + "'>" + o.name + "</option> ";
            }
            $("#specificQuotaId").append(html);
            $('#specificQuotaId').select2();
        });
    }

    function specificSetValue(data) {
        $("#specificId").val(data.id);
        $("#specificWeight").val(data.weight * 100);
        var html = "<option value='" +data.quotaId + "'>" + data.quotaName + "</option> " ;
        $("#specificQuotaId").prepend(html);
        $('#specificQuotaId').select2();
        $("#specificQuotaId option[value='"+data.quotaId+"']").attr("selected","selected") ;
        var url = "/scoremodel/quota/list";
        var map = {
            dimensionId: data.dimensionId
        };
        getReq(url, map, function (result) {
            var html = "";
            for (var i = 0; i < result.length; i++) {
                var o = result.get(i);
                html = html + "<option value='" + o.id + "'>" + o.name + "</option> ";
            }
            $("#specificQuotaId").append(html);
            $('#specificQuotaId').select2();
        });

    }


    function saveSpecificQuotaType() {
        var data = {
            id: $("#specificId").val(),
            modelDimensionId: $("#specificDimensionId").val(),
            weight: $("#specificWeight").val(),
            quotaId: $("#specificQuotaId").val()
        };
        var url = "/scoremodel/quotatype/add";
        if (data.id !== "" && data.id !== undefined) {
            url = "/scoremodel/quotatype/modify";
        }
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                refreshTable('table2');
                $("#addSpecificQuotaTypeModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
